package com.hue.springcloud.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class ConsumerController {
    @Value("${service-url.nacos-user-service}")
    private String url;
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/consumer/findById/{id}")
    @SentinelResource(value = "findById",fallback = "findById_fall")
    public String findById(@PathVariable("id")long id){
        if(id==3){
            throw new RuntimeException("---非法参数异常---");
        }
        return restTemplate.getForObject(url + "/payment/findById/" + id, String.class);
    }
    public String findById_fall(@PathVariable("id")long id,Throwable e){
        return "非法参数异常,参数不能为3,"+e.getMessage();
    }
}
